package org.softmed.rest.server.xstream;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.SingleValueConverter;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class BigDecimalConverter implements SingleValueConverter  {

	public BigDecimalConverter() {

	}

//	@Override
//	public void marshal(Object arg0, HierarchicalStreamWriter arg1,
//			MarshallingContext arg2) {
//		BigDecimal bd = (BigDecimal) arg0;
//		arg1.setValue(bd.toString());
//
//	}
//
//	@Override
//	public Object unmarshal(HierarchicalStreamReader arg0,
//			UnmarshallingContext arg1) {
//
//		BigDecimal bd = new BigDecimal(arg0.getValue());
//		return bd;
//
//	}

	@Override
	public boolean canConvert(Class arg0) {
		// if(true)
		// return true;
		String cname = arg0.getCanonicalName();
		String tname = BigDecimal.class.getCanonicalName();
		boolean result = cname.equals(tname);
		return result;
	}

	@Override
	public Object fromString(String arg0) {
		BigDecimal bd = new BigDecimal(arg0);
		return bd;
	}

	@Override
	public String toString(Object arg0) {
		BigDecimal bd = (BigDecimal) arg0;
		return bd.toString();
	}

}
